package com.amado.course08ArrayTwo;

import java.util.Scanner;

//声明一个二维数组并初始化，求鞍点(所谓鞍点就是这个值在它所在的行最大，在它所在的列最小。) 一个数组只有一个鞍点
//int[][] array = { {1, 3, 5, 4, 2},
//        {12, 23,33,71,23},
//        {14, 23,35,6, 9},
//        {21, 13, 8,9, 2},
//        {67, 81, 92,33, 43}
//        };
//请将数组中的每一行的所有元素向后移动3位(不要移动到下一行去了)。(选做)
public class ArrayTwo15 {
	public static void main(String[] args) {

		// 年级用一个一维数组保存
		int[] grades = new int[100];
		// 班级用一个二维数组保存
		int[][] classes = new int[100][2];
		// 学生也用一个二维数组保存
		int[][] student = new int[100][6];
		// 年级数量
		int gradeCount = 2;
		grades[0] = 1;
		grades[1] = 2;
		// 班级数量
		int classCount = 6;
		classes[0] = new int[] { 1, 1 };
		classes[1] = new int[] { 1, 2 };
		classes[2] = new int[] { 1, 3 };
		classes[3] = new int[] { 2, 1 };
		classes[4] = new int[] { 2, 2 };
		classes[5] = new int[] { 2, 3 };
		// 学生数量
		int stuCount = 7;
		student[0] = new int[] { 1, 1, 1, 1, 1, 18 };
		student[1] = new int[] { 1, 2, 2, 1, 1, 18 };
		student[2] = new int[] { 1, 3, 3, 1, 1, 18 };
		student[3] = new int[] { 2, 1, 4, 1, 1, 18 };
		student[4] = new int[] { 2, 2, 5, 1, 1, 18 };
		student[5] = new int[] { 2, 3, 6, 1, 1, 18 };
		student[6] = new int[] { 2, 3, 7, 1, 1, 18 };
		while (true) {
			System.out.println("一、二、三、删除年级");
			Scanner sc = new Scanner(System.in);
			System.out.println("*请输入要执行的代码*");
			int menu = sc.nextInt();
			if (menu == 3) {
				System.out.println("*请输入要删除的班级*");
				int deleteGrade = sc.nextInt();
				int deleteIndex = -1;
				boolean isExist = false;
				// 查找对应的下标
				for (int i = 0; i < gradeCount; i++) {
					if (deleteGrade == grades[i]) {
						isExist = true;
						deleteIndex = i;
					}
				}
				if (isExist) {
					// 删除年级
					for (int i = deleteIndex; i < gradeCount; i++) {
						grades[i] = grades[i + 1];
						System.out.println("删除成功，年级下标" + i);
					}
					gradeCount--;
					// 删除班级
					deleteIndex = -1;
					int tempClassCount = classCount;
					for (int i = 0; i < tempClassCount; i++) {
						if (deleteGrade == classes[i][0]) {
							System.out.println("删除成功，班级下标" + i);
							for(int j=i;j < tempClassCount;j++){
								classes[j] = classes[j + 1];
							}
							classCount--;
							i--;
						}
					}
					// 删除学生
					int tempStuCount = stuCount;
					for (int i = 0; i < tempStuCount; i++) {
						if (deleteGrade == student[i][0]) {
							System.out.println("删除成功，班级下标" + i);
							for(int j=i;j < tempStuCount;j++){
								student[j] = student[j + 1];
							}
							stuCount--;
							i--;
						}
					}
				} else {
					System.out.println("未找到班级");
				}
			} else if (menu == 4) {
				System.out.println("年级名");
				for (int i = 0; i < gradeCount; i++) {
					// 打印年级一位数组
					System.out.println(grades[i] + "\t\t");
				}
				//班级
				System.out.println("年级名\t年级");
				for (int i = 0; i < classCount; i++) {
					// 打印年级一位数组
					System.out.println(classes[i][0] +"\t"+classes[i][1]);
				}
				//学生
				System.out.println("年级名\t年级名\t学号\t姓名\t性别\t年龄 ");
				for (int i = 0; i < stuCount; i++) {
					// 打印年级一位数组
					System.out.println(student[i][0] +"\t"+student[i][1]+"\t"+student[i][2]+"\t"+student[i][3]+"\t"+student[i][4]+"\t"+student[i][5]);
				}
			}
		}
	}
}
